package org.veridiandynamics.server.domain;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * Invoice object which gives price of particular apppointment.
 *
 */
public class Invoice implements PersistObject, Serializable
{
	private Doctor doctor;
	private long id;
	private Set<ServicesBillable> servicesList;
	

	private static final long serialVersionUID = 60L;
	
	

	
	/**
	 * Constructor that contains list of billable services completed in a particular appointment 
	 * @param itemizedList
	 */
	public Invoice (Map<String, Float> itemizedList){
		
		Set<String> keys = itemizedList.keySet();
		Iterator<String> keyIterator = keys.iterator();
		
		while(keyIterator.hasNext()) 
		{
			String key = keyIterator.next();
			ServicesBillable sBill = new ServicesBillable(key, 
					itemizedList.get(key));
			servicesList.add(sBill);
		}
	}
	

	
	/**
	 * Default constructor.
	 */
	public Invoice()
	{
		
	}
	
	/**
	 * Returns ID
	 * @return long variable of ID
	 */
	public long getId() {
		return id;
	}

	/**
	 * Sets ID 
	 * @param id long variable of ID
	 */
	public void setId(long id) {
		this.id = id;
	}

	/**
	 * Returns set of bill-able services for this invoice.
	 * @return list of <ServicesBillable> objects
	 */
	public Set<ServicesBillable> getServicesList() {
		return servicesList;
	}

	/**
	 * Sets bill-able services for this invoice. 
	 * @param servicesList list of <ServicesBillable> objects
	 */
	public void setServicesList(Set<ServicesBillable> servicesList) {
		this.servicesList = servicesList;
	}

	/**
	 * Returns doctor to be paid for these services.
	 * @return object of type doctor
	 */
	public Doctor getMyDoctor() {
		return doctor;
	}

	/**
	 * Sets doctor to be paid for these services.
	 * @param myDoctor object of type doctor
	 */
	public void setMyDoctor(Doctor myDoctor) {
		this.doctor = myDoctor;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString()
	{
		String retVal = "";
		retVal += doctor.getName()+"\n";
//		retVal+=myAppointment.getStartDate()+"\n";
		for (ServicesBillable i: servicesList)
		{
			retVal += "Services Type: " + i.getService() + "Cost: " + i.getCost() + "\n";
		}
		return retVal;
	}
	

	
	/**
	 * Writes object.
	 * 
	 * @param outputStream
	 * @throws IOException
	 */
	private void writeObject(ObjectOutputStream outputStream) throws IOException {
		outputStream.defaultWriteObject();
	}
	
	/**
	 * Reads object.
	 * 
	 * @param inputStream
	 * @throws ClassNotFoundException
	 * @throws IOException
	 */
	private void readObject(ObjectInputStream inputStream) throws ClassNotFoundException, IOException {
		inputStream.defaultReadObject();
	}
	

}
